package com.lxf.cloudcar.controller;

import com.alibaba.fastjson.JSONObject;
import com.lxf.cloudcar.service.UserCarService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;

/**
 * @author 罗兴发
 * @data 2025/7/29 14:33
 * @description：购物车-控制层
 */
@RestController
@CrossOrigin  //跨域
@RequestMapping("/v1")
@Slf4j
public class UserCarController {

    @Resource
    UserCarService userCarService;
    /**
     * 加入购物车功能
     * @param json
     * @param request
     * @return
     */
    @PostMapping("/addCar")
    public String addCar(@RequestBody JSONObject json, HttpServletRequest request){
        return userCarService.addCar(json,request);
    }

    /**
     * 根据ID删除购物车条目
     *
     * @param json
     * @param request
     * @return
     */
    @PostMapping("/delCarById")
    public String delCarById(@RequestBody JSONObject json, HttpServletRequest request){
        return userCarService.delCarById(json,request);
    }

    /**
     * 更新购物车商品数量
     * @param json
     * @param request
     * @return
     */
    @PostMapping("/updateCarNumById")
    public String updateCarNumById(@RequestBody JSONObject json, HttpServletRequest request){
        return userCarService.updateCarNumById(json,request);
    }

    /**
     * 搜索购物车
     * @param json
     * @param request
     * @return
     */
    @PostMapping("/getCarLikeName")
    public String getCarLikeName(@RequestBody JSONObject json, HttpServletRequest request){
        return userCarService.getCarLikeName(json,request);
    }

    /**
     * 清空car的es数据
     * @return
     */
    @GetMapping("/deleteCarAllEs")
    public String deleteCarAllEs(){
        return userCarService.deleteCarAllEs();
    }
}
